package androidx.blogger.tasks;

import com.google.gwt.user.client.rpc.AsyncCallback;

import androidx.blogger.BloggerApplication;
import androidx.gdata.blogger.BlogEntry;
import androidx.util.GUITask;
import androidx.util.GUITaskQueue;
import androidx.util.ProgressIndicator;

public class DeleteBlogEntryTask implements GUITask {
  private AsyncCallback<BlogEntry> callback;
  private BlogEntry entry;

  public DeleteBlogEntryTask(BlogEntry entry, AsyncCallback<BlogEntry> callback) {
    this.entry = entry;
    this.callback = callback;
  }

  public static void execute(ProgressIndicator progressIndicator, BlogEntry entry,
      AsyncCallback<BlogEntry> callback) {
    GUITaskQueue.getInstance().addTask(progressIndicator, new DeleteBlogEntryTask(entry, callback));
  }


  public void executeNonGuiTask() throws Exception {
    BloggerApplication.getInstance().getServer().deleteBlogEntry(entry);
  }

  public void after_execute() {
    callback.onSuccess(entry);
  }


  public void onFailure(Throwable t) {
    callback.onFailure(t);
  }

}
